﻿// -----------------------------------------------------------------------
// <copyright file="Rule.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Text.RegularExpressions;
using TPTecnicas.MessageProcessor.Common;
using TPTecnicas.MessageProcessor.Business;

namespace TPTecnicas.MessageProcessor.Rules
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class Rule : IRule
    {
        protected IUniversityContext Context;
        protected delegate void StatusUpdate(IMessage message);
        protected event StatusUpdate OnStatusUpdate = null;

        protected Rule(IUniversityContext context)
        {
            Context = context;
        }

        public void Attach(IAction action)
        {
            OnStatusUpdate += action.Execute;
        }

        public void Detach(IAction action)
        {
            OnStatusUpdate -= action.Execute;
        }

        public void Notify(IMessage message)
        {
            if (OnStatusUpdate != null)
            {
                OnStatusUpdate(message);
            }
        }

        public abstract bool Validate(IMessage message);

        protected abstract Match GetMatch(IMessage message);
    }
}
